In [1]:
%load_ext autoreload
%autoreload 2
In [2]:
from skyfield.api import load
import numpy as np
import math
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from skyfield.api import utc
from scipy.optimize import brentq # machine learning

from datetime import timedelta, datetime
import pytz
In [3]:
from definitions import *
In [300]:
from_binary_to_element_symbols = {
    '11': '🜁',
    '01': '🜂',
    '10': '🜄',
    '00': '🜃',
}

# from_binary_to_element_ix = {
#     '11': '0',
#     '01': '1',
#     '10': '2',
#     '00': '3',
# }

from_binary_to_element_ix = {
    '11': '-1',
    '01': '0',
    '10': '1',
    '00': '2',
}
In [301]:
b_to_q = lambda x: [from_binary_to_element_symbols[x[i*2:i*2+2]] for i in [0,1,2]]
b_to_q_el = lambda x: [from_binary_to_element_ix[x[i*2:i*2+2]] for i in [0,1,2]]
In [302]:
from_binary_to_element_symbols['00']
Out[302]:
'🜃'
In [303]:
print ( b_to_q('000000'))
print ( b_to_q_el('101010'))
['🜃', '🜃', '🜃']
['1', '1', '1']
In [304]:
# index elemental composition of the I Ching
iching_ix = [b_to_q_el(str(x['binary']))for x in iching]
In [305]:
# binary position of the I Ching
iching_binary = [b_to_q(str(x['binary']))for x in iching]
In [306]:
# important parameters
design_offset = 88 * math.pi / 180 # required to determine design parameters
earth_offset = math.pi # earth offset (180* against the sun)
pi2 = math.pi*2 # circle constant

# Important parameters and statistics for mandala wheel calculation
hex_width = pi2/64
line_width = hex_width/6
color_width = line_width/6
tone_width = color_width/6
base_width = tone_width/5
In [307]:
# Credits to Ra Uru Hu for receiving this info
iching_map = [36, 22, 63, 37, 55, 30, 49, 13, 19, 41, 60, 61, 54, 38, 58, 10, 11, 26, 5, 9, 34, 14, 43, 1, 44, 28, 50, 32, 57, 48, 18, 46, 6, 47, 64, 40, 59, 29, 4, 7, 33, 31, 56, 62, 53, 39, 52, 15, 12, 45, 35, 16, 20, 8, 23, 2, 24, 27, 3, 42, 51, 21, 17, 25]
iching_map.reverse() 
In [308]:
# how precise decimals are shown in table
pd.set_option('display.float_format', '{:.10f}'.format)
In [309]:
# load Ephemeris
# load library planet position file
planets = load('de431t.bsp')

_planets = {
    "sun": planets['SUN'],
    "earth": planets['EARTH'],
    "moon": planets['MOON'],
    "mercury": planets['MERCURY'],
    "venus": planets['VENUS BARYCENTER'],
    "mars": planets['MARS BARYCENTER'],
    "jupiter": planets['JUPITER BARYCENTER'],
    "saturn": planets['SATURN BARYCENTER'],
    "uranus": planets['URANUS BARYCENTER'],
    "neptune": planets['NEPTUNE BARYCENTER'],
    "pluto": planets['PLUTO BARYCENTER'],
}
In [310]:
ts = load.timescale(builtin=True)

Simple Way

In [311]:
# For iInfo Purposes
# lat = _planets['earth'].at(t_time_array).observe(_planets['venus']).ecliptic_latlon()[0].radians - *math.pi
# lon = _planets['earth'].at(t_time_array).observe(_planets['venus']).ecliptic_latlon()[1].radians - math.pi
# d   = _planets['earth'].at(t_time_array).observe(_planets['venus']).ecliptic_latlon()[2]
In [312]:
def generate_planets(time_range):
    """ Generates a dataframe for the registered collection of dates """
    df = pd.DataFrame()
    df['time'] = np.array(time_range.tt)

    for planet_name, p in _planets.items():
        earth_offset = math.pi if planet_name == "earth" else 0.0
        df[planet_name] = _planets['earth'].at(time_range).observe(p).ecliptic_latlon()[1].radians + earth_offset # latitude
        
    return df
In [313]:
hours_in_100_years = 24 * 365 * 10
t_time_array = ts.utc(2010, 1, 1, range(0,hours_in_100_years), 0) # -3000 BC to 3000 BC, increments in hours

df_planets = generate_planets(t_time_array) # takes a while
/Users/blvck/miniconda3/envs/ds_starter/lib/python3.7/site-packages/skyfield/functions.py:60: RuntimeWarning: divide by zero encountered in true_divide
  theta = arcsin(z / r)
/Users/blvck/miniconda3/envs/ds_starter/lib/python3.7/site-packages/skyfield/functions.py:60: RuntimeWarning: invalid value encountered in true_divide
  theta = arcsin(z / r)
/Users/blvck/miniconda3/envs/ds_starter/lib/python3.7/site-packages/skyfield/functions.py:60: RuntimeWarning: invalid value encountered in arcsin
  theta = arcsin(z / r)
In [314]:
t_time_array[0]
Out[314]:
<Time tt=2455197.500766019>
In [315]:
df_planets.tail()
Out[315]:
time sun earth moon mercury venus mars jupiter saturn uranus neptune pluto
87595 2458847.2924326854 4.8430998981 3.1415926536 5.5718318039 4.7237048836 5.4354951159 4.1299740076 4.8152313872 5.0766074393 0.5661538211 6.0379774112 5.0971295605
87596 2458847.3340993519 4.8438412701 3.1415926536 5.5807373298 4.7248425179 5.4363875792 4.1304624685 4.8153990169 5.0766920783 0.5661461710 6.0379906416 5.0971533294
87597 2458847.3757660189 4.8445826421 3.1415926536 5.5896363789 4.7259802905 5.4372800222 4.1309509389 4.8155666457 5.0767767259 0.5661385463 6.0380038877 5.0971771018
87598 2458847.4174326854 4.8453240144 3.1415926536 5.5985290190 4.7271182016 5.4381724448 4.1314394187 4.8157342738 5.0768613820 0.5661309472 6.0380171496 5.0972008776
87599 2458847.4590993519 4.8460653867 3.1415926536 5.6074153091 4.7282562515 5.4390648471 4.1319279081 4.8159019010 5.0769460468 0.5661233735 6.0380304273 5.0972246570
In [316]:
len(df_planets)
Out[316]:
87600

Add Elemental Component To It

In [317]:
import math
In [318]:
math.pi
Out[318]:
3.141592653589793
In [23]:
# for one rad, return array of elements

# for one row, return array of elements

# for one 
In [24]:
df_planets.apply(lambda x: x/(math.pi**2))
Out[24]:
time sun earth moon mercury venus mars jupiter saturn uranus neptune pluto
0 248763.5168533225 0.4957016664 0.3183098862 0.1823108484 0.5108119730 0.4911017644 0.2452199542 0.5768811606 0.3260229937 0.6241482892 0.5737393835 0.4830712400
1 248763.5210750385 0.4957767303 0.3183098862 0.1834188271 0.5107368774 0.4911944714 0.2452085475 0.5768960660 0.3260246713 0.6241501517 0.5737415423 0.4830738959
2 248763.5252967545 0.4958517943 0.3183098862 0.1845271608 0.5106613036 0.4912871783 0.2451970990 0.5769109757 0.3260263434 0.6241520167 0.5737437023 0.4830765516
3 248763.5295184705 0.4959268583 0.3183098862 0.1856358317 0.5105852552 0.4913798850 0.2451856088 0.5769258897 0.3260280101 0.6241538839 0.5737458634 0.4830792071
4 248763.5337401865 0.4960019225 0.3183098862 0.1867448214 0.5105087358 0.4914725917 0.2451740768 0.5769408080 0.3260296713 0.6241557536 0.5737480257 0.4830818625
5 248763.5379619024 0.4960769868 0.3183098862 0.1878541099 0.5104317488 0.4915652983 0.2451625031 0.5769557305 0.3260313270 0.6241576257 0.5737501891 0.4830845176
6 248763.5421836185 0.4961520512 0.3183098862 0.1889636760 0.5103542979 0.4916580049 0.2451508876 0.5769706574 0.3260329773 0.6241595001 0.5737523536 0.4830871725
7 248763.5464053344 0.4962271157 0.3183098862 0.1900735044 0.5102763869 0.4917507113 0.2451392304 0.5769855885 0.3260346221 0.6241613769 0.5737545193 0.4830898272
8 248763.5506270504 0.4963021803 0.3183098862 0.1911835738 0.5101980194 0.4918434177 0.2451275314 0.5770005239 0.3260362615 0.6241632561 0.5737566861 0.4830924817
9 248763.5548487664 0.4963772450 0.3183098862 0.1922938629 0.5101191991 0.4919361240 0.2451157908 0.5770154636 0.3260378953 0.6241651376 0.5737588540 0.4830951361
10 248763.5590704824 0.4964523099 0.3183098862 0.1934043555 0.5100399300 0.4920288302 0.2451040084 0.5770304075 0.3260395238 0.6241670216 0.5737610231 0.4830977902
11 248763.5632921983 0.4965273749 0.3183098862 0.1945150311 0.5099602159 0.4921215364 0.2450921843 0.5770453558 0.3260411467 0.6241689079 0.5737631933 0.4831004441
12 248763.5675139144 0.4966024400 0.3183098862 0.1956258689 0.5098800606 0.4922142425 0.2450803185 0.5770603082 0.3260427642 0.6241707965 0.5737653646 0.4831030978
13 248763.5717356303 0.4966775052 0.3183098862 0.1967368523 0.5097994681 0.4923069485 0.2450684110 0.5770752650 0.3260443762 0.6241726876 0.5737675371 0.4831057513
14 248763.5759573463 0.4967525705 0.3183098862 0.1978479597 0.5097184424 0.4923996544 0.2450564617 0.5770902260 0.3260459828 0.6241745810 0.5737697107 0.4831084046
15 248763.5801790623 0.4968276360 0.3183098862 0.1989591718 0.5096369875 0.4924923603 0.2450444708 0.5771051912 0.3260475838 0.6241764768 0.5737718854 0.4831110577
16 248763.5844007783 0.4969027016 0.3183098862 0.2000704707 0.5095551075 0.4925850661 0.2450324382 0.5771201608 0.3260491794 0.6241783750 0.5737740613 0.4831137106
17 248763.5886224943 0.4969777673 0.3183098862 0.2011818363 0.5094728065 0.4926777718 0.2450203639 0.5771351345 0.3260507696 0.6241802755 0.5737762383 0.4831163633
18 248763.5928442103 0.4970528331 0.3183098862 0.2022932479 0.5093900886 0.4927704774 0.2450082480 0.5771501125 0.3260523542 0.6241821784 0.5737784164 0.4831190158
19 248763.5970659262 0.4971278991 0.3183098862 0.2034046897 0.5093069580 0.4928631830 0.2449960904 0.5771650948 0.3260539334 0.6241840837 0.5737805956 0.4831216680
20 248763.6012876422 0.4972029652 0.3183098862 0.2045161390 0.5092234191 0.4929558885 0.2449838911 0.5771800813 0.3260555071 0.6241859913 0.5737827760 0.4831243201
21 248763.6055093582 0.4972780315 0.3183098862 0.2056275772 0.5091394760 0.4930485940 0.2449716501 0.5771950720 0.3260570754 0.6241879014 0.5737849575 0.4831269719
22 248763.6097310742 0.4973530978 0.3183098862 0.2067389872 0.5090551330 0.4931412994 0.2449593675 0.5772100669 0.3260586381 0.6241898137 0.5737871401 0.4831296235
23 248763.6139527902 0.4974281644 0.3183098862 0.2078503479 0.5089703946 0.4932340047 0.2449470432 0.5772250661 0.3260601954 0.6241917285 0.5737893239 0.4831322750
24 248763.6181745062 0.4975032310 0.3183098862 0.2089616394 0.5088852652 0.4933267100 0.2449346773 0.5772400696 0.3260617472 0.6241936456 0.5737915088 0.4831349261
25 248763.6223962222 0.4975782978 0.3183098862 0.2100728462 0.5087997490 0.4934194152 0.2449222698 0.5772550772 0.3260632935 0.6241955651 0.5737936948 0.4831375771
26 248763.6266179381 0.4976533648 0.3183098862 0.2111839453 0.5087138508 0.4935121204 0.2449098206 0.5772700891 0.3260648344 0.6241974869 0.5737958819 0.4831402279
27 248763.6308396542 0.4977284318 0.3183098862 0.2122949211 0.5086275748 0.4936048255 0.2448973298 0.5772851052 0.3260663697 0.6241994111 0.5737980701 0.4831428784
28 248763.6350613701 0.4978034991 0.3183098862 0.2134057527 0.5085409258 0.4936975305 0.2448847974 0.5773001255 0.3260678996 0.6242013376 0.5738002595 0.4831455287
29 248763.6392830861 0.4978785665 0.3183098862 0.2145164222 0.5084539082 0.4937902355 0.2448722234 0.5773151500 0.3260694240 0.6242032666 0.5738024500 0.4831481788
... ... ... ... ... ... ... ... ... ... ... ... ...
87570 249133.2125221375 0.4888307106 0.3183098862 0.5417577938 0.4757341915 0.5484695066 0.4172168816 0.4874603158 0.5141537724 0.0573835912 0.6117420263 0.5163871112
87571 249133.2167438535 0.4889058260 0.3183098862 0.5426781972 0.4758491155 0.5485599821 0.4172663490 0.4874773013 0.5141623255 0.0573827517 0.6117433267 0.5163895103
87572 249133.2209655695 0.4889809414 0.3183098862 0.5435978235 0.4759640529 0.5486504557 0.4173158173 0.4874942867 0.5141708795 0.0573819148 0.6117446287 0.5163919098
87573 249133.2251872855 0.4890560570 0.3183098862 0.5445166763 0.4760790037 0.5487409273 0.4173652866 0.4875112721 0.5141794345 0.0573810804 0.6117459322 0.5163943096
87574 249133.2294090014 0.4891311726 0.3183098862 0.5454347592 0.4761939680 0.5488313969 0.4174147569 0.4875282575 0.5141879904 0.0573802486 0.6117472375 0.5163967099
87575 249133.2336307174 0.4892062883 0.3183098862 0.5463520770 0.4763089458 0.5489218646 0.4174642281 0.4875452429 0.5141965472 0.0573794194 0.6117485443 0.5163991105
87576 249133.2378524334 0.4892814040 0.3183098862 0.5472686334 0.4764239371 0.5490123303 0.4175137003 0.4875622283 0.5142051049 0.0573785927 0.6117498527 0.5164015115
87577 249133.2420741494 0.4893565199 0.3183098862 0.5481844320 0.4765389419 0.5491027940 0.4175631734 0.4875792136 0.5142136636 0.0573777686 0.6117511627 0.5164039128
87578 249133.2462958654 0.4894316358 0.3183098862 0.5490994781 0.4766539603 0.5491932557 0.4176126476 0.4875961990 0.5142222232 0.0573769471 0.6117524744 0.5164063145
87579 249133.2505175814 0.4895067518 0.3183098862 0.5500137755 0.4767689923 0.5492837155 0.4176621226 0.4876131843 0.5142307837 0.0573761281 0.6117537877 0.5164087166
87580 249133.2547392974 0.4895818678 0.3183098862 0.5509273282 0.4768840378 0.5493741733 0.4177115987 0.4876301696 0.5142393451 0.0573753117 0.6117551025 0.5164111191
87581 249133.2589610133 0.4896569839 0.3183098862 0.5518401417 0.4769990970 0.5494646291 0.4177610757 0.4876471549 0.5142479075 0.0573744979 0.6117564190 0.5164135220
87582 249133.2631827293 0.4897321001 0.3183098862 0.5527522191 0.4771141699 0.5495550829 0.4178105537 0.4876641401 0.5142564707 0.0573736867 0.6117577371 0.5164159252
87583 249133.2674044453 0.4898072163 0.3183098862 0.5536635671 0.4772292564 0.5496455347 0.4178600326 0.4876811253 0.5142650349 0.0573728781 0.6117590568 0.5164183288
87584 249133.2716261613 0.4898823326 0.3183098862 0.5545741894 0.4773443567 0.5497359844 0.4179095125 0.4876981105 0.5142735999 0.0573720720 0.6117603781 0.5164207327
87585 249133.2758478773 0.4899574489 0.3183098862 0.5554840906 0.4774594706 0.5498264322 0.4179589934 0.4877150956 0.5142821659 0.0573712685 0.6117617010 0.5164231371
87586 249133.2800695933 0.4900325653 0.3183098862 0.5563932764 0.4775745983 0.5499168780 0.4180084752 0.4877320806 0.5142907328 0.0573704675 0.6117630255 0.5164255417
87587 249133.2842913092 0.4901076817 0.3183098862 0.5573017514 0.4776897398 0.5500073218 0.4180579580 0.4877490657 0.5142993005 0.0573696692 0.6117643516 0.5164279468
87588 249133.2885130253 0.4901827981 0.3183098862 0.5582095194 0.4778048950 0.5500977635 0.4181074417 0.4877660506 0.5143078692 0.0573688734 0.6117656793 0.5164303522
87589 249133.2927347412 0.4902579146 0.3183098862 0.5591165884 0.4779200641 0.5501882032 0.4181569264 0.4877830355 0.5143164387 0.0573680802 0.6117670086 0.5164327580
87590 249133.2969564572 0.4903330311 0.3183098862 0.5600229623 0.4780352470 0.5502786409 0.4182064121 0.4878000204 0.5143250092 0.0573672896 0.6117683395 0.5164351641
87591 249133.3011781732 0.4904081477 0.3183098862 0.5609286455 0.4781504438 0.5503690766 0.4182558987 0.4878170052 0.5143335805 0.0573665016 0.6117696720 0.5164375706
87592 249133.3053998892 0.4904832643 0.3183098862 0.5618336453 0.4782656544 0.5504595102 0.4183053863 0.4878339899 0.5143421527 0.0573657161 0.6117710062 0.5164399775
87593 249133.3096216051 0.4905583809 0.3183098862 0.5627379659 0.4783808790 0.5505499418 0.4183548749 0.4878509746 0.5143507258 0.0573649333 0.6117723419 0.5164423847
87594 249133.3138433212 0.4906334975 0.3183098862 0.5636416134 0.4784961175 0.5506403713 0.4184043644 0.4878679591 0.5143592998 0.0573641530 0.6117736792 0.5164447923
87595 249133.3180650371 0.4907086142 0.3183098862 0.5645445934 0.4786113700 0.5507307988 0.4184538549 0.4878849437 0.5143678746 0.0573633753 0.6117750181 0.5164472002
87596 249133.3222867531 0.4907837309 0.3183098862 0.5654469118 0.4787266364 0.5508212243 0.4185033463 0.4879019281 0.5143764504 0.0573626002 0.6117763586 0.5164496085
87597 249133.3265084691 0.4908588476 0.3183098862 0.5663485740 0.4788419169 0.5509116476 0.4185528387 0.4879189125 0.5143850270 0.0573618276 0.6117777007 0.5164520172
87598 249133.3307301851 0.4909339643 0.3183098862 0.5672495869 0.4789572114 0.5510020690 0.4186023321 0.4879358967 0.5143936044 0.0573610577 0.6117790445 0.5164544262
87599 249133.3349519011 0.4910090810 0.3183098862 0.5681499563 0.4790725200 0.5510924882 0.4186518264 0.4879528809 0.5144021827 0.0573602903 0.6117803898 0.5164568355

87600 rows × 12 columns

In [25]:
import seaborn as sns
In [26]:
normalize_squared = lambda x: x/(math.pi**2)
normalize = lambda x: x/(math.pi)
# df_planets.apply(lambda x: x/(math.pi**2))
In [27]:
df_planets['earth'] = df_planets['sun'] - math.pi
In [28]:
sns.lineplot(x='time', y='earth', data=df_planets[:2000])
Out[28]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff4a44c1e80>
In [29]:
sns.lineplot(x='time', y='sun', data=df_planets.apply(normalize)[:2000])
Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff48bcbd828>
In [30]:
sns.lineplot(x='time', y='sun', data=df_planets.apply(normalize_squared)[:2000])
Out[30]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff48c5b5240>

Define several functions

In [31]:
def neutron_stream_pos(planet_position):
    """ returns mandala position (base 64) given planet position"""
    return ( (planet_position  + (2*line_width - 1*color_width - 2*tone_width) ) / (2*math.pi) * 64) % 64
In [32]:
def map_on_hexagram(df):
    """ maps df planet positions onto position onto a hexagram and line """
    # convert dataframe to numpy array
    neutron_stream = df.to_numpy()

    hexagram_bin = np.floor(neutron_stream) # rounded up downwards

    # map bin number onto 'hexagram' (neutron stream is sequential order, hexagram is King Wen Sequence)
    strong = np.array(iching_map)
    flat = hexagram_bin.astype(int).flatten()

    previous_shape = neutron_stream.shape
    mapped = strong[flat]

    hexagram = mapped.reshape(previous_shape)
    hexagram_fraction = neutron_stream - hexagram_bin

    line = hexagram_fraction // (1/6) + 1 # count in which 6th this neutrino stream falls in
    line_fraction = (hexagram_fraction - (line - 1)*1/6 ) / (1/6)

    color = line_fraction // (1/6) + 1
    color_fraction = (line_fraction - (color -1) * 1/6) / (1/6)

    tone = color_fraction // (1/6) + 1

    return hexagram #, line.astype(int), color.astype(int), tone.astype(int)
In [33]:
# map 'neutron' stream, aka influences of the probability field (the planets in the solar system physical space)
df_angles = neutron_stream_pos(df_planets.iloc[:, 1:6])
z = map_on_hexagram(df_angles)
z
Out[33]:
array([[38, 39, 39, 54, 58],
       [38, 39, 39, 54, 58],
       [38, 39, 39, 54, 58],
       ...,
       [58, 52, 49, 10, 19],
       [58, 52, 49, 10, 19],
       [58, 52, 49, 10, 19]])
In [34]:
many_2_b = np.array(iching_binary) # strong
many_2 = np.array(iching_ix) # strong
one_2 = z.astype(int).flatten() - 1 # flat
In [35]:
many_2_b[63]
Out[35]:
array(['🜄', '🜄', '🜄'], dtype='<U1')
In [36]:
# binary el
el_b = many_2_b[one_2]

# normal el (0 -> 3)
el = many_2[one_2]
el_b
Out[36]:
array([['🜄', '🜄', '🜁'],
       ['🜂', '🜂', '🜃'],
       ['🜂', '🜂', '🜃'],
       ...,
       ['🜂', '🜁', '🜂'],
       ['🜁', '🜄', '🜁'],
       ['🜃', '🜃', '🜁']], dtype='<U1')
In [37]:
el.shape
Out[37]:
(438000, 3)
In [38]:
z.shape
Out[38]:
(87600, 5)
In [39]:
el.reshape((87600, 5, 3))
Out[39]:
array([[['2', '2', '0'],
        ['1', '1', '3'],
        ['1', '1', '3'],
        ['3', '2', '0'],
        ['1', '2', '0']],

       [['2', '2', '0'],
        ['1', '1', '3'],
        ['1', '1', '3'],
        ['3', '2', '0'],
        ['1', '2', '0']],

       [['2', '2', '0'],
        ['1', '1', '3'],
        ['1', '1', '3'],
        ['3', '2', '0'],
        ['1', '2', '0']],

       ...,

       [['1', '2', '0'],
        ['2', '1', '3'],
        ['1', '0', '1'],
        ['0', '2', '0'],
        ['3', '3', '0']],

       [['1', '2', '0'],
        ['2', '1', '3'],
        ['1', '0', '1'],
        ['0', '2', '0'],
        ['3', '3', '0']],

       [['1', '2', '0'],
        ['2', '1', '3'],
        ['1', '0', '1'],
        ['0', '2', '0'],
        ['3', '3', '0']]], dtype='<U1')
In [40]:
finish = el.reshape((87600, 15))
finish
Out[40]:
array([['2', '2', '0', ..., '1', '2', '0'],
       ['2', '2', '0', ..., '1', '2', '0'],
       ['2', '2', '0', ..., '1', '2', '0'],
       ...,
       ['1', '2', '0', ..., '3', '3', '0'],
       ['1', '2', '0', ..., '3', '3', '0'],
       ['1', '2', '0', ..., '3', '3', '0']], dtype='<U1')
In [41]:
df_finish = pd.DataFrame(finish)
df_finish.head(20)
Out[41]:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 2 2 0 1 1 3 1 1 3 3 2 0 1 2 0
1 2 2 0 1 1 3 1 1 3 3 2 0 1 2 0
2 2 2 0 1 1 3 1 1 3 3 2 0 1 2 0
3 2 2 0 1 1 3 1 1 3 3 2 0 1 2 0
4 2 2 0 1 1 3 0 1 3 3 2 0 1 2 0
5 2 2 0 1 1 3 0 1 3 3 2 0 1 2 0
6 2 2 0 1 1 3 0 1 3 3 2 0 1 2 0
7 2 2 0 1 1 3 0 1 3 3 2 0 1 2 0
8 2 2 0 1 1 3 0 1 3 3 2 0 1 2 0
9 2 2 0 1 1 3 0 1 3 3 2 0 1 2 0
10 2 2 0 1 1 3 0 1 3 3 2 0 1 2 0
11 2 2 0 1 1 3 0 1 3 3 2 0 1 2 0
12 2 2 0 1 1 3 0 1 3 3 2 0 1 2 0
13 2 2 0 1 1 3 3 0 3 3 2 0 1 2 0
14 2 2 0 1 1 3 3 0 3 3 2 0 1 2 0
15 2 2 0 1 1 3 3 0 3 3 2 0 1 2 0
16 2 2 0 1 1 3 3 0 3 3 2 0 1 2 0
17 2 2 0 1 1 3 3 0 3 3 2 0 1 2 0
18 2 2 0 1 1 3 3 0 3 3 2 0 1 2 0
19 2 2 0 1 1 3 3 0 3 3 2 0 1 2 0
In [42]:
import seaborn as sns
In [43]:
uniform_data = np.random.rand(10, 12)
In [44]:
data = finish.astype(int)
In [45]:
data[1:5].shape
Out[45]:
(4, 15)
In [46]:
ax = sns.heatmap(data[1:10])
In [47]:
ax = sns.heatmap(data[1:50])
In [48]:
ax = sns.heatmap(data[1:100])
In [49]:
ax = sns.heatmap(data[1:500])
In [50]:
ax = sns.heatmap(data[1:3000])

let's add extra time to see how this progresses

In [51]:
ax = sns.heatmap(data[3000:6000])
In [52]:
ax = sns.heatmap(data[6000:9000])
In [53]:
ax = sns.heatmap(data[9000:12000])
In [54]:
ax = sns.heatmap(data[12000:15000])
In [55]:
ax = sns.heatmap(data[0:10000])
In [56]:
ax = sns.heatmap(data[0:80000])
In [ ]:
 
In [57]:
water = sns.color_palette("tab10")[0]
air = sns.color_palette("tab10")[1]
earth = sns.color_palette("tab10")[2]
fire = sns.color_palette("tab10")[3]
color_map = [air, fire, water, earth]
In [58]:
fig, ax = plt.subplots(figsize=(10,50))
sns.heatmap(data[0:10000], ax=ax, cmap=color_map, cbar=False)
Out[58]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff492542e48>
In [59]:
data.transpose()
Out[59]:
array([[2, 2, 2, ..., 1, 1, 1],
       [2, 2, 2, ..., 2, 2, 2],
       [0, 0, 0, ..., 0, 0, 0],
       ...,
       [1, 1, 1, ..., 3, 3, 3],
       [2, 2, 2, ..., 3, 3, 3],
       [0, 0, 0, ..., 0, 0, 0]])
In [ ]:
 
In [60]:
one_year = 24 * 365
In [61]:
fig, ax = plt.subplots(figsize=(50,5))
sns.heatmap(data[one_year*0:one_year*1].transpose(), ax=ax, cmap=color_map, cbar=False)
Out[61]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff48da35a90>
In [62]:
fig, ax = plt.subplots(figsize=(50,5))
sns.heatmap(data[one_year*1:one_year*2].transpose(), ax=ax, cmap=color_map, cbar=False)
Out[62]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff48c923780>
In [63]:
fig, ax = plt.subplots(figsize=(50,5))
sns.heatmap(data[one_year*2:one_year*3].transpose(), ax=ax, cmap=color_map, cbar=False)
Out[63]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff48c82ca90>
In [64]:
fig, ax = plt.subplots(figsize=(50,5))
sns.heatmap(data[one_year*3:one_year*4].transpose(), ax=ax, cmap=color_map, cbar=False)
Out[64]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff492383518>
In [ ]:
 

More Experiments

There's something wrong with the currently presented mapping, as it doesn't show fire-fire-fire (63) nor water-water-water (64). This causes a lot of randomness which can be best dealt with from the start, before any further iteration occurs.

In [71]:
data_fixed = finish.astype(int)
In [72]:
water = "#0E61B0"
air = "#C29F17"
earth = "#55A349"
fire = "#C9280C"
color_map = [air, fire, water, earth]
In [73]:
fig, ax = plt.subplots(figsize=(50,5))
sns.heatmap(data_fixed[one_year*0:one_year*1].transpose(), ax=ax, cmap=color_map, cbar=False)
Out[73]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff4953b1128>
In [74]:
## add a few planets
In [75]:
data_tmp = get_elemental_map(df_planets.loc[:,['earth','moon','mercury','venus','sun', 'mars', 'jupiter','saturn', 'uranus','neptune']])

fig, ax = plt.subplots(figsize=(50,10))
sns.heatmap(data_tmp[one_year*0:one_year*1].transpose(), ax=ax, cmap=color_map, cbar=False)
Out[75]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff4966af048>

2019-2021

In [79]:
hours_in_desired_timespan = 24 * 365 * 2 # 2 years in hours
t_time_array = ts.utc(2019, 1, 1, range(0,hours_in_desired_timespan), 0) # -3000 BC to 3000 BC, increments in hours

df_planets_2019_2020 = generate_planets(t_time_array) # takes a while
In [80]:
r = ['earth','moon','mercury','venus','sun', 'mars', 'jupiter','saturn', 'uranus','neptune']
r.reverse()
In [81]:
data_tmp = get_elemental_map(df_planets_2019_2020.loc[:,r])

fig, ax = plt.subplots(figsize=(50,15))
sns.heatmap(data_tmp.transpose(), ax=ax, cmap=color_map, cbar=False)
Out[81]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff48f0f00b8>
In [83]:
print (t_time_array[0].utc_datetime())
print (t_time_array[hours_in_desired_timespan-1].utc_datetime())
2019-01-01 00:00:00+00:00
2020-12-30 23:00:00+00:00
In [ ]:
 
In [ ]:
 

Add crypto data

In [84]:
import pandas as pd
import numpy as np
In [85]:
df_c = pd.read_csv('Binance_BTCUSDT_1h.csv', parse_dates=True)
In [86]:
df_c['date'].dtype
Out[86]:
dtype('O')
In [87]:
df_c['date'] = pd.to_datetime(df_c['unix'], unit='ms')
In [88]:
df_money = df_c.set_index('date')
In [89]:
df_money['close'].plot()
Out[89]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff495f1a518>
In [90]:
len(df_money)
Out[90]:
3169
In [92]:
df_money
Out[92]:
unix symbol open high low close Volume BTC Volume USDT tradecount
date
2020-12-12 00:00:00 1607731200000 BTC/USDT 18036.5300000000 18167.7200000000 18020.7000000000 18167.7200000000 933.7434350000 16906972.5914758407 16220
2020-12-11 23:00:00 1607727600000 BTC/USDT 18127.8100000000 18149.7500000000 18012.6900000000 18036.5300000000 1824.6197360000 32973409.5444627814 42841
2020-12-11 22:00:00 1607724000000 BTC/USDT 18100.0100000000 18184.0000000000 18067.7200000000 18127.8100000000 1977.1300930000 35865598.6473629996 46808
2020-12-11 21:00:00 1607720400000 BTC/USDT 17983.4700000000 18125.1800000000 17952.1500000000 18100.0100000000 2363.5838950000 42645696.8699249923 41747
2020-12-11 20:00:00 1607716800000 BTC/USDT 17975.0800000000 18060.0000000000 17925.3700000000 17982.8900000000 2012.4993960000 36169523.1231627986 37353
2020-12-11 19:00:00 1607713200000 BTC/USDT 18044.2600000000 18093.9500000000 17959.2200000000 17977.0000000000 2055.8029590000 37101541.7850096971 32395
2020-12-11 18:00:00 1607709600000 BTC/USDT 17995.5000000000 18046.8300000000 17943.2900000000 18044.2600000000 1971.8828310000 35487541.9007753283 29206
2020-12-11 17:00:00 1607706000000 BTC/USDT 17978.1500000000 18007.0000000000 17852.0000000000 17995.5300000000 2771.2965770000 49724633.9460585117 41311
2020-12-11 16:00:00 1607702400000 BTC/USDT 18104.7400000000 18111.5500000000 17942.8500000000 17978.1400000000 2468.6478510000 44465838.9578887597 37065
2020-12-11 15:00:00 1607698800000 BTC/USDT 18058.7500000000 18132.0000000000 18028.0000000000 18104.7400000000 3191.4236030000 57668403.5110896230 39004
2020-12-11 14:00:00 1607695200000 BTC/USDT 17972.0000000000 18068.0000000000 17901.0700000000 18058.7600000000 3657.4385670000 65772843.0251502991 49362
2020-12-11 13:00:00 1607691600000 BTC/USDT 17864.7300000000 17987.9800000000 17827.6800000000 17972.0100000000 2900.7712500000 51946637.4957306832 46985
2020-12-11 12:00:00 1607688000000 BTC/USDT 17647.7100000000 17916.5000000000 17617.0000000000 17864.7300000000 4028.5924360000 71630940.1987653971 56403
2020-12-11 11:00:00 1607684400000 BTC/USDT 17758.4600000000 17761.1000000000 17600.0000000000 17647.7100000000 3575.2656250000 63181227.8751152381 57844
2020-12-11 10:00:00 1607680800000 BTC/USDT 17802.6000000000 17874.0100000000 17572.3300000000 17758.4500000000 5006.2343840000 88775697.6424745172 66490
2020-12-11 09:00:00 1607677200000 BTC/USDT 17899.4600000000 17908.0000000000 17728.2500000000 17802.6000000000 2599.6716770000 46295339.8942571878 39175
2020-12-11 08:00:00 1607673600000 BTC/USDT 17811.9600000000 18001.1500000000 17810.5000000000 17898.7900000000 3799.9668970000 67987197.4929697663 52485
2020-12-11 07:00:00 1607670000000 BTC/USDT 17923.6000000000 17944.8700000000 17700.5100000000 17811.9500000000 3651.8614890000 64968977.4109107479 58596
2020-12-11 06:00:00 1607666400000 BTC/USDT 17899.4300000000 17968.0000000000 17814.7300000000 17923.6000000000 1844.1011720000 33002682.3578775004 32584
2020-12-11 05:00:00 1607662800000 BTC/USDT 17959.7300000000 18021.4200000000 17833.8800000000 17899.4400000000 2208.2442520000 39566413.0945991129 33090
2020-12-11 04:00:00 1607659200000 BTC/USDT 17990.6900000000 18048.6000000000 17929.8100000000 17959.7200000000 2129.2112710000 38281486.7172628418 30298
2020-12-11 03:00:00 1607655600000 BTC/USDT 17804.9700000000 17996.1400000000 17715.6000000000 17990.8800000000 3471.1345710000 62034423.2410548776 52850
2020-12-11 02:00:00 1607652000000 BTC/USDT 17901.4400000000 18040.8100000000 17801.3700000000 17804.9700000000 3702.9779580000 66344001.6844175309 57712
2020-12-11 01:00:00 1607648400000 BTC/USDT 18018.3100000000 18074.8000000000 17804.0000000000 17901.4500000000 5573.6719700000 99914282.9393186271 75607
2020-12-11 00:00:00 1607644800000 BTC/USDT 18254.8100000000 18292.7300000000 17950.0000000000 18018.3200000000 3824.6937990000 69277307.9522603452 60599
2020-12-10 23:00:00 1607641200000 BTC/USDT 18326.3600000000 18380.4100000000 18220.0000000000 18254.6300000000 1461.8671890000 26759875.4073627889 27870
2020-12-10 22:00:00 1607637600000 BTC/USDT 18348.9900000000 18397.7700000000 18297.7600000000 18326.3600000000 1007.9417830000 18487455.9629814290 26372
2020-12-10 21:00:00 1607634000000 BTC/USDT 18365.7900000000 18405.6200000000 18305.7400000000 18349.0000000000 1405.9401100000 25819451.1810251214 27157
2020-12-10 20:00:00 1607630400000 BTC/USDT 18403.1100000000 18435.7400000000 18342.5600000000 18365.7800000000 2400.9416050000 44171460.1445000097 34522
2020-12-10 19:00:00 1607626800000 BTC/USDT 18274.7400000000 18403.2800000000 18225.3100000000 18403.1000000000 2437.6196420000 44650435.5630260631 34483
... ... ... ... ... ... ... ... ... ...
2020-08-03 04:00:00 1596427200000 BTC/USDT 11136.2700000000 11187.2300000000 11132.4300000000 11171.3200000000 1083.2573880000 12093959.9817282893 21708
2020-08-03 03:00:00 1596423600000 BTC/USDT 11178.5500000000 11194.6400000000 11115.0700000000 11136.4700000000 1666.9290490000 18604582.5111420415 25458
2020-08-03 02:00:00 1596420000000 BTC/USDT 11117.9700000000 11207.8800000000 11117.9700000000 11178.6500000000 1779.6322160000 19879626.5958632194 34273
2020-08-03 01:00:00 1596416400000 BTC/USDT 11135.3000000000 11179.1000000000 11108.1100000000 11117.9700000000 1768.0361910000 19704216.8905645683 33848
2020-08-03 00:00:00 1596412800000 BTC/USDT 11071.3600000000 11144.7700000000 10936.0000000000 11135.3000000000 2773.2881950000 30671167.3823490813 48318
2020-08-02 23:00:00 1596409200000 BTC/USDT 11118.3200000000 11139.2400000000 11032.2500000000 11071.3500000000 1537.4746200000 17062586.2248780914 31723
2020-08-02 22:00:00 1596405600000 BTC/USDT 11132.7600000000 11187.0100000000 11104.0000000000 11118.3200000000 1583.2414770000 17650800.6555211283 30453
2020-08-02 21:00:00 1596402000000 BTC/USDT 11087.9800000000 11155.2500000000 11000.0000000000 11132.7600000000 2084.3587890000 23118467.5012499616 50398
2020-08-02 20:00:00 1596398400000 BTC/USDT 11202.8000000000 11219.4800000000 11080.6000000000 11087.9800000000 2108.3318500000 23500785.1484060809 37471
2020-08-02 19:00:00 1596394800000 BTC/USDT 11228.9500000000 11266.1200000000 11117.6500000000 11202.8000000000 2333.2945180000 26114438.1350217089 38106
2020-08-02 18:00:00 1596391200000 BTC/USDT 11263.0700000000 11268.9200000000 11198.4800000000 11229.0500000000 1871.9655390000 21036184.6920579784 34210
2020-08-02 17:00:00 1596387600000 BTC/USDT 11201.8600000000 11283.4100000000 11170.0000000000 11263.0700000000 2748.4607710000 30856082.1457497403 48718
2020-08-02 16:00:00 1596384000000 BTC/USDT 11083.6200000000 11212.8900000000 11064.0100000000 11201.2400000000 3067.6431750000 34218179.8547646180 47688
2020-08-02 15:00:00 1596380400000 BTC/USDT 11137.4400000000 11152.4600000000 11072.8900000000 11083.6300000000 2108.1143090000 23437919.4887556806 37035
2020-08-02 14:00:00 1596376800000 BTC/USDT 11109.4300000000 11179.1000000000 11059.8400000000 11137.3700000000 2570.4032670000 28595971.0142107084 43965
2020-08-02 13:00:00 1596373200000 BTC/USDT 10993.3900000000 11133.4700000000 10979.9100000000 11109.4400000000 2670.6159500000 29605369.8519478887 47171
2020-08-02 12:00:00 1596369600000 BTC/USDT 11105.5400000000 11173.7600000000 10960.0000000000 10996.2500000000 4328.2077660000 47949280.1087244824 68754
2020-08-02 11:00:00 1596366000000 BTC/USDT 11251.3100000000 11271.7900000000 10931.0000000000 11109.8600000000 7149.7874750000 79324987.1693886071 91331
2020-08-02 10:00:00 1596362400000 BTC/USDT 11305.4100000000 11319.9500000000 11122.0100000000 11251.3000000000 3366.1736650000 37819339.4597343728 52992
2020-08-02 09:00:00 1596358800000 BTC/USDT 11281.6400000000 11315.0000000000 11227.2400000000 11306.8100000000 2514.9341120000 28373101.0543438494 39761
2020-08-02 08:00:00 1596355200000 BTC/USDT 11325.9500000000 11342.8300000000 11263.1300000000 11281.8000000000 3374.2789400000 38159485.8235544786 55216
2020-08-02 07:00:00 1596351600000 BTC/USDT 11293.3300000000 11371.5100000000 11254.3600000000 11323.7800000000 3704.5255750000 41987500.5778870508 58772
2020-08-02 06:00:00 1596348000000 BTC/USDT 11251.7600000000 11320.0000000000 11202.0000000000 11293.3300000000 3609.6752010000 40731553.2565946877 69200
2020-08-02 05:00:00 1596344400000 BTC/USDT 11170.8000000000 11410.4000000000 11111.8800000000 11252.1400000000 9098.5795700000 102672449.3908934742 137266
2020-08-02 04:00:00 1596340800000 BTC/USDT 11999.9600000000 12123.4600000000 10518.5000000000 11169.8400000000 21611.3977480000 245741865.5798097551 226807
2020-08-02 03:00:00 1596337200000 BTC/USDT 11928.4000000000 12000.0000000000 11870.0000000000 12000.0000000000 3746.4227430000 44731714.5875343084 59258
2020-08-02 02:00:00 1596333600000 BTC/USDT 11942.5400000000 11965.0100000000 11892.8800000000 11928.5800000000 3785.4155590000 45157950.4532752410 51092
2020-08-02 01:00:00 1596330000000 BTC/USDT 11782.6300000000 11942.5500000000 11772.1300000000 11942.5500000000 3707.1368010000 44004705.9416337088 55304
2020-08-02 00:00:00 1596326400000 BTC/USDT 11801.1700000000 11857.0000000000 11740.0000000000 11782.6300000000 2872.6381840000 33906617.4122241363 47209
2020-08-01 23:00:00 1596322800000 BTC/USDT 11783.3100000000 11820.6100000000 11731.7100000000 11801.1700000000 2194.5985890000 25849742.1258138716 37272

3169 rows × 9 columns

In [98]:
hours_in_trading_code = len(df_money) # stock exchange count of number differences
t_time_array = ts.utc(2020, 8, 1, range(0,hours_in_trading_code), 0) # -3000 BC to 3000 BC, increments in hours

df_crypto_2_months = generate_planets(t_time_array) # takes a while
In [101]:
r = ['earth','moon','mercury','venus','sun', 'mars', 'jupiter','saturn', 'uranus','neptune']
r.reverse()

data_tmp = get_elemental_map(df_crypto_2_months.loc[:,r])

fig, ax = plt.subplots(figsize=(15,15))
sns.heatmap(data_tmp.transpose(), ax=ax, cmap=color_map, cbar=False)
Out[101]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff49ac46518>
In [103]:
fig, ax = plt.subplots(figsize=(15,15))
df_money['close'].plot()
Out[103]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff47ced0320>
In [124]:
df_solar = pd.DataFrame(data_tmp)
df_solar.index = df_money.index
#df_money.loc[['close']].join(df_solar)
df_dataset = pd.concat([df_money[['close']], df_solar], axis=1)
In [125]:
df_dataset.head()
Out[125]:
close 0 1 2 3 4 5 6 7 8 ... 20 21 22 23 24 25 26 27 28 29
date
2020-12-12 00:00:00 18167.7200000000 2 1 1 3 3 1 1 3 0 ... 3 3 0 3 1 2 0 3 3 0
2020-12-11 23:00:00 18036.5300000000 2 1 1 3 3 1 1 3 0 ... 3 3 0 3 1 2 0 3 3 0
2020-12-11 22:00:00 18127.8100000000 2 1 1 3 3 1 1 3 0 ... 3 3 0 3 1 2 0 3 3 0
2020-12-11 21:00:00 18100.0100000000 2 1 1 3 3 1 1 3 0 ... 3 3 0 3 1 2 0 3 3 0
2020-12-11 20:00:00 17982.8900000000 2 1 1 3 3 1 1 3 0 ... 3 3 0 3 1 2 0 3 3 0

5 rows × 31 columns

Simple Training

In [ ]:
from sklearn import svm
In [129]:
len(df_dataset)
Out[129]:
3169
In [ ]:
train_size = 0.8
In [ ]:
 
In [145]:
df_x = df_dataset[df_dataset.columns[1:]]
df_y = df_dataset['close']
In [157]:
train_x = df_x[:3000]
train_y = df_y[:3000]

test_x = df_x[3000:]
test_y = df_y[3000:]
In [158]:
from sklearn import svm
In [167]:
X = train_x.to_numpy()
y = train_y.to_numpy()
regr = svm.SVR(kernel='poly', C=100, gamma=0.1, epsilon=.1)
regr.fit(X, y)
Out[167]:
SVR(C=100, cache_size=200, coef0=0.0, degree=3, epsilon=0.1, gamma=0.1,
    kernel='poly', max_iter=-1, shrinking=True, tol=0.001, verbose=False)
In [178]:
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
In [179]:
results.plot()
Out[179]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff47e939198>
In [181]:
results = pd.DataFrame()
results['test_x'] = regr.predict(train_x)
results['test_y'] = list(train_y)
results.plot()
Out[181]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff47e9ec898>

Moving to more data (Bitstamp)

In [328]:
df_hourly.iloc[0].name.year
Out[328]:
2019
In [347]:
df_solar.index
Out[347]:
RangeIndex(start=0, stop=8317, step=1)
In [354]:
def get_crypto_planet_data(size):
    df_c = pd.read_csv('bitstampUSD_1-min_data_2012-01-01_to_2020-09-14.csv', parse_dates=True)

    # make data timestamp
    df_c['date'] = pd.to_datetime(df_c['Timestamp'], unit='s')

    # cast down to hourly data
    groupkey = pd.to_datetime(df_c[-size:].date.dt.strftime('%Y-%m-%d %H'))
    df_hourly = df_c[-size:].groupby(groupkey).agg({'Close':'last','Volume_(BTC)':'sum'})
    df_hourly.head()

    first_date = df_hourly.iloc[0].name
    print ( first_date )

    # generate ephemerial elements
    h = first_date.hour
    hours_in_trading_code = len(df_hourly) # stock exchange count of number differences
    t_time_array = ts.utc(first_date.year, first_date.month, first_date.day, range(h,h+hours_in_trading_code), 0) # -3000 BC to 3000 BC, increments in hours


    # generate empheremis for time period
    df_crypto_planets = generate_planets(t_time_array) # can take a while

    # selected desired planets for attribution
    r = ['earth','moon','mercury','venus','sun', 'mars', 'jupiter','saturn', 'uranus','neptune']
    r.reverse()

    # create elemental data map
    data_tmp = get_elemental_map(df_crypto_planets.loc[:,r])

    # plot data map
    fig, ax = plt.subplots(figsize=(5,5))
    sns.heatmap(data_tmp.transpose(), ax=ax, cmap=color_map, cbar=False)

    # create the training dataset [Close, Solar System Time]
    df_solar = pd.DataFrame(data_tmp)
    df_solar.index = df_hourly.index
    #df_money.loc[['close']].join(df_solar)
    df_dataset = pd.concat([df_hourly[['Close']], df_solar], axis=1)
    return df_dataset
In [355]:
get_data = get_crypto_planet_data(1000000)
len(get_data)
2018-10-20 13:00:00
Out[355]:
16668
In [231]:
df_c = pd.read_csv('bitstampUSD_1-min_data_2012-01-01_to_2020-09-14.csv', parse_dates=True)
In [187]:
# make data timestamp
df_c['date'] = pd.to_datetime(df_c['Timestamp'], unit='s')
In [209]:
len(df_c[-50000:])
Out[209]:
50000
In [218]:
# cast down to hourly data
groupkey = pd.to_datetime(df_c[-500000:].date.dt.strftime('%Y-%m-%d %H'))
df_hourly = df_c[-500000:].groupby(groupkey).agg({'Close':'last','Volume_(BTC)':'sum'})
df_hourly.head()
Out[218]:
Close Volume_(BTC)
date
2019-10-02 18:00:00 8237.8000000000 78.2375346900
2019-10-02 19:00:00 8264.8400000000 83.8577731100
2019-10-02 20:00:00 8226.8200000000 193.6398213700
2019-10-02 21:00:00 8266.1100000000 88.3407354300
2019-10-02 22:00:00 8278.1000000000 116.2889901200
In [219]:
len(df_hourly)
Out[219]:
8335
In [222]:
df_hourly.plot()
Out[222]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff46a331048>
In [225]:
df_hourly.iloc[0]
Out[225]:
Close          8237.8000000000
Volume_(BTC)     78.2375346900
Name: 2019-10-02 18:00:00, dtype: float64
In [226]:
# generate ephemerial elements
hours_in_trading_code = len(df_hourly) # stock exchange count of number differences
t_time_array = ts.utc(2019, 10, 2, range(0,hours_in_trading_code), 0) # -3000 BC to 3000 BC, increments in hours

df_crypto_2_months = generate_planets(t_time_array) # takes a while

r = ['earth','moon','mercury','venus','sun', 'mars', 'jupiter','saturn', 'uranus','neptune']
r.reverse()

data_tmp = get_elemental_map(df_crypto_2_months.loc[:,r])

fig, ax = plt.subplots(figsize=(5,5))
sns.heatmap(data_tmp.transpose(), ax=ax, cmap=color_map, cbar=False)
Out[226]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff338725b38>
In [228]:
# create the training dataset
df_solar = pd.DataFrame(data_tmp)
df_solar.index = df_hourly.index
#df_money.loc[['close']].join(df_solar)
df_dataset = pd.concat([df_hourly[['Close']], df_solar], axis=1)
df_dataset.head()
Out[228]:
Close 0 1 2 3 4 5 6 7 8 ... 20 21 22 23 24 25 26 27 28 29
date
2019-10-02 18:00:00 8237.8000000000 1 1 1 2 3 1 2 2 0 ... 2 2 0 2 1 0 0 1 2 1
2019-10-02 19:00:00 8264.8400000000 1 1 1 2 3 1 2 2 0 ... 2 2 0 2 1 0 0 1 2 1
2019-10-02 20:00:00 8226.8200000000 1 1 1 2 3 1 2 2 0 ... 2 2 0 2 1 0 0 1 2 1
2019-10-02 21:00:00 8266.1100000000 1 1 1 2 3 1 2 2 0 ... 2 2 0 2 2 0 0 1 2 1
2019-10-02 22:00:00 8278.1000000000 1 1 1 2 3 1 2 2 0 ... 2 2 0 2 2 0 0 1 2 1

5 rows × 31 columns

In [ ]:
df_dataset
In [235]:
df_dataset.Close.dtype
Out[235]:
dtype('float64')
In [ ]:
 
In [ ]:
 
In [ ]:
from sklearn import svm
In [275]:
# prepaire dataset for training
df_x = df_dataset[df_dataset.columns[1:]]
df_x = df_x[df_dataset['Close'].isnull() != True]
df_y = df_dataset['Close'].dropna()

# we train on this
train_x = df_x[:6000]
train_y = df_y[:6000]

# we test on this (validate)
test_x = df_x[6000:]
test_y = df_y[6000:]
In [276]:
test_x.shape
Out[276]:
(2331, 30)
In [277]:
df_y[df_y.isnull() == True]
Out[277]:
Series([], Name: Close, dtype: float64)
In [282]:
X = train_x.to_numpy()
y = train_y.to_numpy()
regr = svm.SVR(kernel='linear', C=100, gamma=0.1, epsilon=.1)
regr.fit(X, y)
Out[282]:
SVR(C=100, cache_size=200, coef0=0.0, degree=3, epsilon=0.1, gamma=0.1,
    kernel='poly', max_iter=-1, shrinking=True, tol=0.001, verbose=False)
In [280]:
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
Out[280]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff33912f2e8>
In [281]:
# adjust for start
In [291]:
# train the model
X = train_x.to_numpy()
y = train_y.to_numpy()
regr = svm.SVR(kernel='rbf', C=100, gamma=0.001, epsilon=.1)
regr.fit(X, y)
Out[291]:
SVR(C=100, cache_size=200, coef0=0.0, degree=3, epsilon=0.1, gamma=0.001,
    kernel='rbf', max_iter=-1, shrinking=True, tol=0.001, verbose=False)
In [292]:
# see results
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
Out[292]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff33ae91a90>
In [293]:
# train the model
X = train_x.to_numpy()
y = train_y.to_numpy()
regr = svm.SVR(kernel='rbf', C=1000, gamma=0.001, epsilon=.1)
regr.fit(X, y)

# see results
results = pd.DataFrame()
results[''] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
Out[293]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff33ab6d320>
In [298]:
start_offset = results['test_y'][0] - results['test_x'][0]
results['test_x'] += start_offset
In [299]:
results.plot()
Out[299]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff33cc21be0>

Regenerate Dataset with alternative labeling: -1, 0, 1, 2

In [356]:
get_data = get_crypto_planet_data(1000000)
len(get_data)
2018-10-20 13:00:00
Out[356]:
16668
In [357]:
# prepaire dataset for training
df_x = get_data[get_data.columns[1:]]
df_x = df_x[get_data['Close'].isnull() != True]
df_y = get_data['Close'].dropna()

# we train on this
train_x = df_x[:10000].to_numpy()
train_y = df_y[:10000].to_numpy()

# we test on this (validate)
test_x = df_x[10000:]
test_y = df_y[10000:]
In [358]:
# train model
regr = svm.SVR(kernel='linear', C=100, gamma=0.1, epsilon=.1)
regr.fit(train_x, train_y)
Out[358]:
SVR(C=100, cache_size=200, coef0=0.0, degree=3, epsilon=0.1, gamma=0.1,
    kernel='linear', max_iter=-1, shrinking=True, tol=0.001, verbose=False)
In [359]:
# see results
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
Out[359]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff2ee7c86d8>
In [361]:
# train the model
regr = svm.SVR(kernel='rbf', C=100, gamma=0.001, epsilon=.1)
regr.fit(train_x, train_y)

# see results
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
Out[361]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff2ef041f28>
In [366]:
results = pd.DataFrame()
results['test_x'] = np.diff(regr.predict(test_x))
results['test_y'] = np.diff(list(test_y))
results.plot()
Out[366]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff2ee34ee10>
In [367]:
# train the model
regr = svm.SVR(kernel='rbf', C=1000, gamma=0.001, epsilon=.01)
regr.fit(train_x, train_y)

# see results
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
Out[367]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff2ef0aac18>
In [372]:
# train the model
regr = svm.SVR(kernel='poly', C=100, gamma=0.01, epsilon=.1)
regr.fit(train_x, train_y)

# see results
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
Out[372]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff2fa80be80>
In [375]:
# train the model
regr = svm.SVR(kernel='sigmoid', C=100, gamma=0.001, epsilon=.0001)
regr.fit(train_x, train_y)

# see results
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
Out[375]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff2faf66518>
In [ ]:
 

Time to add dummy data to the rotators

In [420]:
get_data = get_crypto_planet_data(1000000)
len(get_data)
2018-10-20 13:00:00
Out[420]:
16668
In [ ]:
 
In [421]:
get_data.columns = ['Close']+ [str(x)+'_pl' for x in get_data.iloc[:,1:].columns]
In [422]:
get_data.columns
Out[422]:
Index(['Close', '0_pl', '1_pl', '2_pl', '3_pl', '4_pl', '5_pl', '6_pl', '7_pl',
       '8_pl', '9_pl', '10_pl', '11_pl', '12_pl', '13_pl', '14_pl', '15_pl',
       '16_pl', '17_pl', '18_pl', '19_pl', '20_pl', '21_pl', '22_pl', '23_pl',
       '24_pl', '25_pl', '26_pl', '27_pl', '28_pl', '29_pl'],
      dtype='object')
In [423]:
get_data.iloc[:,1:] = get_data.iloc[:,1:].astype(str)
In [426]:
get_data_flat = pd.get_dummies(get_data.iloc[:,1:])
In [429]:
get_data_flat['Close'] = get_data.Close
In [430]:
# prepaire dataset for training
df_x = get_data_flat[get_data_flat.columns[1:]]
df_x = df_x[get_data_flat['Close'].isnull() != True]
df_y = get_data_flat['Close'].dropna()

# we train on this
train_x = df_x[:10000].to_numpy()
train_y = df_y[:10000].to_numpy()

# we test on this (validate)
test_x = df_x[10000:]
test_y = df_y[10000:]
In [431]:
# train the model
regr = svm.SVR(kernel='rbf', C=100, gamma=0.001, epsilon=.1)
regr.fit(train_x, train_y)

# see results
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
Out[431]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff3d7b22128>
In [442]:
from sklearn.metrics import explained_variance_score, mean_squared_error, r2_score
In [443]:
print ("Explained Variance:",explained_variance_score(results['test_y'].to_numpy(), results['test_x'].to_numpy()))
print ("MSE:", mean_squared_error(results['test_y'].to_numpy(), results['test_x'].to_numpy()))
print ("R2",r2_score(results['test_y'].to_numpy(), results['test_x'].to_numpy()))
Explained Variance: 0.8866200576497931
MSE: 298048.39375166624

Are you fucking shitting me that the algorithm almost 1:1 predicted whole 2020, based on 2019 data.

We're literally seeing 0.8866 variance explained... BY PLANET POSITIONS?

In [ ]:
 
In [ ]:
# train the model
regr = svm.SVR(kernel='poly', C=100, gamma=0.001, epsilon=.01)
regr.fit(train_x, train_y)

# see results
results = pd.DataFrame()
results['test_x'] = regr.predict(test_x)
results['test_y'] = list(test_y)
results.plot()
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 

Animate

In [58]:
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as ani
import numpy as np
import pandas as pd
from celluloid import Camera

fig = plt.figure()
camera = Camera(fig) #  https://pypi.org/project/celluloid/
# ax1 = plt.subplot2grid ((2, 2), (0, 0), colspan=2, rowspan=2)
for i in range(30):
    #data = np.random.normal(0, 10, i+1)
    #pd.DataFrame(data).plot(kind='bar', ax=ax1)

    ax = sns.heatmap(data[i*50:2000+i*50], cbar=False)
    # ax._legend().remove()
    camera.snap()

# Set up formatting for the movie files
Writer = ani.writers['ffmpeg']
writer = Writer(fps=30, metadata=dict(artist='Me'), bitrate=1800)

# anim = ani.ArtistAnimation(fig, ims, interval=500, repeat_delay=3000, blit=True)
anim = camera.animate(interval=50000, repeat_delay=5000)
anim.save('textmovie.mp4', writer=writer)

Let's re-arrange the order of the planets

In [70]:
def get_elemental_map(df_planets):
    # map 'neutron' stream, aka influences of the probability field (the planets in the solar system physical space)
    # position to index on a wheel
    
    df_planets['earth'] = df_planets['sun'] - math.pi
    df_angles = neutron_stream_pos(df_planets)

    # index on a wheel to specific binary I-Ching Sequence - King Wen Version
    z = map_on_hexagram(df_angles)
    
    many_2_b = np.array(iching_binary) # strong
    many_2 = np.array(iching_ix) # strong
    one_2 = z.astype(int).flatten() - 1 # flat

    # binary el
    el_b = many_2_b[one_2]

    # normal el (0 -> 3)
    el = many_2[one_2]
    
    finish = el.reshape((df_angles.shape[0], df_angles.shape[1]*3))

    return finish.astype(int)
In [131]:
temp = get_elemental_map(df_planets.loc[:,['earth','moon','mercury','venus','sun', 'mars', 'jupiter','saturn', 'uranus','neptune']])
temp
Out[131]:
array([[2, 1, 2, ..., 0, 0, 2],
       [2, 1, 2, ..., 0, 0, 2],
       [2, 1, 2, ..., 0, 0, 2],
       ...,
       [3, 1, 2, ..., 2, 1, 2],
       [3, 1, 2, ..., 2, 1, 2],
       [3, 1, 2, ..., 2, 1, 2]])
In [132]:
ax = sns.heatmap(temp[1:500])
In [133]:
ax = sns.heatmap(temp[1:3000])

ladies and gentlemen, we're looking at the jaws of a new discovery in our universe

In [ ]:
 
In [ ]:
 
In [134]:
ax = sns.heatmap(temp[1:30000])
ERROR:root:Invalid alias: The name clear can't be aliased because it is another magic command.
ERROR:root:Invalid alias: The name more can't be aliased because it is another magic command.
ERROR:root:Invalid alias: The name less can't be aliased because it is another magic command.
ERROR:root:Invalid alias: The name man can't be aliased because it is another magic command.
In [70]:
df_planets.columns
Out[70]:
Index(['time', 'sun', 'earth', 'moon', 'mercury', 'venus', 'mars', 'jupiter',
       'saturn', 'uranus', 'neptune', 'pluto'],
      dtype='object')
In [ ]:
 
In [ ]:
 
In [ ]:
 

Adding Time-Split Into Cyclical Variables

We want to convert the julian-time to a series of values of increment

In [141]:
t = df.time[0]
t
Out[141]:
2415020.5004882407
In [742]:
def test_get_buckets(j_tt, mod_period):
    for index, rotor in enumerate(range(-10,9)):
        print ( math.floor(j_tt % (mod_period**rotor) / (mod_period**rotor) * mod_period) , '%', (mod_period**rotor))
        
def value_to_rotor(j_tt, mod_period, n_rotor_range_min=-15, n_rotor_range_max=15):
    """ Returns rotary bins. Mod_periods=2 returns binary. mod_period=10 returns decimal arrangement
    
        Good default value for n_rotor_range = 10 (this defines how many rotors there are)
    """
    rotor = []
    for r in range(n_rotor_range_min, n_rotor_range_max):
        rot = math.floor(j_tt % (mod_period**r) / (mod_period**r) * mod_period)
        rotor.append(rot)

    return rotor

def rotor_to_value(rotor, mod_period, n_rotor_range_min=-15, n_rotor_range_max=15):
    """ Converts rotary bins back to a decimal value """
    
    julian_time = 0.0
    print (n_rotor_range_min, n_rotor_range_max)
    for index, r in enumerate(range(n_rotor_range_min, n_rotor_range_max)):

        julian_time += rotor[index] * (mod_period**(r+1)) / (mod_period**2)
    
    return julian_time

def encode_value_to_one_hot_rotor(value, mod_period, n_rotor_range_min=-15, n_rotor_range_max=15):
    """ Converts a value to a 1-hot encoded rotor array """
    values = value_to_rotor(value, mod_period, n_rotor_range_min, n_rotor_range_max) # get time rotation of j_tt (julian)
    n_values = mod_period # = max value of period
    return np.eye(n_values)[values].flatten()

def decode_one_hot_rotor_to_value(flat_1hot_rotor, mod_period, n_rotor_range_min=-15, n_rotor_range_max=15):
    """ Converts a one hot rotor back to a value """
    
    # convert to the numpy useful one-hot encoding of the different bins (there mod_period amount in every encoding)
    onehot = np.reshape(flat_1hot_rotor, (int(len(flat_1hot_rotor)/mod_period),mod_period))
    
    # get rotor values (1hot -> category array)
    rotor = np.argmax(onehot, axis=1)
    
    # convert to value
    value = rotor_to_value(rotor, mod_period, n_rotor_range_min, n_rotor_range_max)
    
    return value
In [734]:
# small little test for the bucketing system
print (df.time[0])
test_get_buckets(df.time[0], 10) # test
2415020.5004882407
4 % 1e-10
5 % 1e-09
0 % 1e-08
4 % 1e-07
2 % 1e-06
8 % 1e-05
8 % 0.0001
4 % 0.001
0 % 0.01
0 % 0.1
5 % 1
0 % 10
2 % 100
0 % 1000
5 % 10000
1 % 100000
4 % 1000000
2 % 10000000
0 % 100000000
In [735]:
# below snippet is how to create categorical variables
values = [1, 0, 3]
categories = np.eye(4)[values] # 4 categories
categories
Out[735]:
array([[0., 1., 0., 0.],
       [1., 0., 0., 0.],
       [0., 0., 0., 1.]])
In [736]:
# back to category array
np.argmax(categories, axis=1)
Out[736]:
array([1, 0, 3])
In [737]:
# further testing
r = value_to_rotor(df.time[0], 4, -15, 15)
print ("Julian time:", df.time[0])
print("to")
print ("Rotor encoded:",r)
Julian time: 2415020.5004882407
to
Rotor encoded: [2, 0, 1, 1, 3, 3, 3, 3, 3, 3, 1, 0, 0, 0, 0, 2, 0, 3, 2, 2, 1, 2, 1, 3, 0, 1, 2, 0, 0, 0]
In [744]:
_t = rotor_to_value(r, 4, -15, 15)
print("Rotor encoded:",r)
print("to")
print("Julian Time from rotor", _t)
-15 15
Rotor encoded: [2, 0, 1, 1, 3, 3, 3, 3, 3, 3, 1, 0, 0, 0, 0, 2, 0, 3, 2, 2, 1, 2, 1, 3, 0, 1, 2, 0, 0, 0]
to
Julian Time from rotor 2415020.5004882407
In [ ]:
 
In [845]:
def test_encode_decode(value, mod_rotor, n_rotor_range_min, n_rotor_range_max):

    a_time_rotor = encode_value_to_one_hot_rotor(value, mod_rotor, n_rotor_range_min, n_rotor_range_max)
    value_decoded = decode_one_hot_rotor_to_value(a_time_rotor, mod_rotor, n_rotor_range_min, n_rotor_range_max)
    print ("Julian time:", value)
    print ("Flat One Hot Array:", a_time_rotor, " with length:", len(a_time_rotor))
    print ("Decoded Rotor:", value_decoded)
    print ("Error:", value_decoded - value)
In [846]:
test_encode_decode(df.time[1000], 4, -15, 15)
-15 15
Julian time: 2415062.1671549077
Flat One Hot Array: [0. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 1. 0. 0. 0. 0. 1. 0.
 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 1. 0. 0. 0. 0. 0. 0. 1.
 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 1. 0. 0. 0. 0. 0. 1. 0. 0. 1. 0. 0.
 0. 1. 0. 0. 0. 0. 0. 1. 0. 1. 0. 0. 0. 0. 1. 0. 0. 1. 0. 0. 0. 0. 0. 1.
 1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0.]  with length: 120
Decoded Rotor: 2415062.1671549077
Error: 0.0

We'll be adding all these arrays to a dataframe, then transposing it to get the dummy values.

In [762]:
# this might take a time... It creates a dataframe from a series of values (like a column)
def value_array_to_rotor_df(value_array, prefix="_", mod_rotor = 4, n_rotor_range_min=-15, n_rotor_range_max=15):

    encode = np.zeros((len(value_array),mod_rotor*(n_rotor_range_max-n_rotor_range_min)))

    # do it across our time_range (currently in use)
    time_rotors = []
    for ii, t in enumerate(value_array):
        encode[ii,:] = np.array(encode_value_to_one_hot_rotor(t, mod_rotor, n_rotor_range_min, n_rotor_range_max))

    df_rotor = pd.DataFrame(encode)
    df_rotor = df_rotor.add_prefix(prefix)

    return df_rotor
In [764]:
df_time_rotor = value_array_to_rotor_df(t_time_array.tt, "time_rot_", 4, -15, 15)
In [765]:
df_time_rotor.head()
Out[765]:
time_rot_0 time_rot_1 time_rot_2 time_rot_3 time_rot_4 time_rot_5 time_rot_6 time_rot_7 time_rot_8 time_rot_9 ... time_rot_110 time_rot_111 time_rot_112 time_rot_113 time_rot_114 time_rot_115 time_rot_116 time_rot_117 time_rot_118 time_rot_119
0 0.0000000000 0.0000000000 1.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
1 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
2 1.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
3 0.0000000000 0.0000000000 1.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
4 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000

5 rows × 120 columns

In [766]:
len(df_time_rotor)
Out[766]:
876000
In [767]:
encode.shape
Out[767]:
(100, 120)

Now add time_rot_ to df_planets, containing our ephimeris. It essentially displays time as a series of buckets

In [768]:
df_planets_with_trotor = df_planets.merge(df_time_rotor, left_index=True, right_index=True)
df_planets_with_trotor.head()
Out[768]:
time sun earth moon mercury venus mars jupiter saturn uranus ... time_rot_110 time_rot_111 time_rot_112 time_rot_113 time_rot_114 time_rot_115 time_rot_116 time_rot_117 time_rot_118 time_rot_119
0 2415020.5004882407 4.9139988284 3.1415926536 4.7790792273 4.5447599779 5.3716391230 4.9788254865 4.2329877905 4.6969294963 4.3901325057 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
1 2415020.5421549077 4.9147404218 3.1415926536 4.7895000534 4.5456886992 5.3725433572 4.9793857048 4.2331299323 4.6970140338 4.3901726600 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
2 2415020.5838215742 4.9154820157 3.1415926536 4.7999305701 4.5466182272 5.3734475816 4.9799459428 4.2332720395 4.6970985632 4.3902128023 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
3 2415020.6254882407 4.9162236103 3.1415926536 4.8103706577 4.5475485580 5.3743517962 4.9805062005 4.2334141122 4.6971830845 4.3902529325 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
4 2415020.6671549077 4.9169652056 3.1415926536 4.8208202389 4.5484796881 5.3752560010 4.9810664780 4.2335561504 4.6972675976 4.3902930506 ... 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000

5 rows × 132 columns

We quickly check if the values are correctly encoded:

In [769]:
# Testing of time rotor values

filter_col = [col for col in df_planets_with_trotor if col.startswith('time_rot_')]

print ("Julian Time:",df_planets_with_trotor.loc[5500,'time'])
rot = np.array(df_planets_with_trotor.loc[5500,filter_col])
print ("Rotor:", rot)
Julian Time: 2415249.6671549077
Rotor: [0. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 1. 0. 0. 0. 0. 1. 0.
 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 1. 0. 0. 0. 0. 0. 0. 1.
 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 1. 0. 0. 1. 0. 0. 0.
 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 1. 0. 0. 0. 0. 0. 1.
 1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0.]
In [771]:
decode_one_hot_rotor_to_value(rot, 4, -15, 15)
-15 15
Out[771]:
2415249.6671549077

Converting Planet Angles to One-Hot Encodings

In [773]:
print (df_planets_with_trotor.jupiter.min()  * 180.0 / math.pi )
print (df_planets_with_trotor.jupiter.max()  * 180.0 / math.pi )
0.0003493438621863469
359.9999345420169

First let's determine optimale rotor_count (range)

In [832]:
print ("Our maximum difference between 2 values is is maximum this value", df_planets_with_trotor.sun.diff().max())
print ("So let's not add useless precision to the onehot encoding")
Our maximum difference between 2 values is is maximum this value 0.0007415992627457513
So let's not add useless precision to the onehot encoding
In [853]:
val = df_planets_with_trotor.sun.max()
test_encode_decode(val, 4, -10, 3) # optimale parameters for 0 error

val = df_planets_with_trotor.sun.min()
test_encode_decode(val, 4, -10, 3) # optimale parameters for 0 error
-10 3
Julian time: 6.283182822518666
Flat One Hot Array: [0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 1.
 0. 1. 0. 0. 1. 0. 0. 0. 0. 0. 1. 0. 1. 0. 0. 0. 0. 1. 0. 0. 0. 0. 1. 0.
 0. 1. 0. 0.]  with length: 52
Decoded Rotor: 6.283182621002197
Error: -2.0151646840105286e-07
-10 3
Julian time: 1.331978542433677e-05
Flat One Hot Array: [0. 0. 0. 1. 0. 1. 0. 0. 0. 0. 0. 1. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0.
 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0. 1. 0. 0. 0.
 1. 0. 0. 0.]  with length: 52
Decoded Rotor: 1.3113021850585938e-05
Error: -2.0676357375083306e-07

Above errors are small enough to proceed with this encoding.

Let's proceed with encoding all planets

In [839]:
planets = ['moon', 'mercury', 'venus', 'sun', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune', 'pluto']
In [842]:
for planet_name in planets:
    print ("Encoding:", planet_name)
    # calculate rotor for planet
    df_planet_rotor = \
        value_array_to_rotor_df(df_planets_with_trotor[planet_name], planet_name+"_rot_", 4, -10, 3)
        
    # add planet to `df_planets_with_trotor`
    df_planets_with_trotor = df_planets_with_trotor.merge(df_planet_rotor, left_index=True, right_index=True)
    
Encoding: moon
Encoding: mercury
Encoding: venus
Encoding: sun
Encoding: mars
Encoding: jupiter
Encoding: saturn
Encoding: uranus
Encoding: neptune
Encoding: pluto
In [849]:
df_planets_with_trotor.drop('earth', axis=1, inplace=True)
df_planets_with_trotor.head()
Out[849]:
time sun moon mercury venus mars jupiter saturn uranus neptune ... pluto_rot_42 pluto_rot_43 pluto_rot_44 pluto_rot_45 pluto_rot_46 pluto_rot_47 pluto_rot_48 pluto_rot_49 pluto_rot_50 pluto_rot_51
0 2415020.5004882407 4.9139988284 4.7790792273 4.5447599779 5.3716391230 4.9788254865 4.2329877905 4.6969294963 4.3901325057 1.5115380264 ... 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
1 2415020.5421549077 4.9147404218 4.7895000534 4.5456886992 5.3725433572 4.9793857048 4.2331299323 4.6970140338 4.3901726600 1.5115182044 ... 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
2 2415020.5838215742 4.9154820157 4.7999305701 4.5466182272 5.3734475816 4.9799459428 4.2332720395 4.6970985632 4.3902128023 1.5114983874 ... 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
3 2415020.6254882407 4.9162236103 4.8103706577 4.5475485580 5.3743517962 4.9805062005 4.2334141122 4.6971830845 4.3902529325 1.5114785754 ... 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000
4 2415020.6671549077 4.9169652056 4.8208202389 4.5484796881 5.3752560010 4.9810664780 4.2335561504 4.6972675976 4.3902930506 1.5114587685 ... 0.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 1.0000000000 0.0000000000 0.0000000000 0.0000000000

5 rows × 651 columns

In [852]:
df_planets_with_trotor.to_csv("100_year_rotor_encoded_ephemeris.csv", sep=';', index=False)
In [854]:
len (df_planets_with_trotor)
Out[854]:
876000

Next steps

  • Divide dataset in 1/2 (50 years), one for training, one for testing
  • Setup input training data:
    • X = Time Rotor input (120)
    • Y = 52 (1 observed sphere) -> the moon (use script to get columns starting with "moonrot"

When more planets will be active, the loss algorithm should be taking an argmax across "planet rotors", so that the neural network learns the "sphere grouping" across outputs (520 when taking all spheres into account).

We train till the precision will be small enough, say E <= 0.00001, should be adequate enough I think.

Then we validate the data on the other 50 years, and we're very anxious for the results.

In [ ]:
 

Old School Way

In [13]:
def planet1_looks_at_planet2(p1, p2, t):
    return p1.at(t).observe(p2).apparent()

def observe(p1, p2, t):
    """ Observe planet 1 to planet 2 ... observe(p1, p2, timestamp).degrees, or use .radians for radiance """
    t = get_ts(t)

    astrometric = planet1_looks_at_planet2(p1, p2, t)
    _, lon, _ = astrometric.ecliptic_latlon()
    return lon

def getEarthPos(t, planet):
    """ Given a time t and planet p, return longitude position of planet on ecliptic plane """

    return observe(_planets['earth'], planet, t).radians
In [14]:
t = datetime(1, 12, 9, 0, 14, 0, tzinfo=utc)
In [15]:
t
Out[15]:
datetime.datetime(1, 12, 9, 0, 14, tzinfo=<UTC>)
In [5]:
t = datetime(1970, 12, 9, 0, 14, 0, tzinfo=utc)
earth = _planets['earth']
jupiter = _planets['jupiter']
observe(earth, jupiter, t).radians
Out[5]:
4.072675942197303

Generate a whole set of dates, spaced every 2H

In [6]:
start = datetime(1970, 1, 1, 0, 0, 0, tzinfo=utc)
end = datetime(2020, 4, 12, 0, 0, 0, tzinfo=utc)
dates = pd.date_range(start = start, end = end, tz=pytz.UTC, freq='2H').to_pydatetime().tolist()

# reason for 2H frequency: we want to divide the day up in 12 segments, which is a nice amount
len(dates)
Out[6]:
220369
In [75]:
import math
In [102]:
bodies = ['sun', 'earth', 'moon', 'venus', 'mars', 'jupiter']

positions = {
    'sun': (lambda t: observe(earth,      _planets['sun'], t).radians),
    'earth': (lambda t: observe(earth,    _planets['sun'], t).radians - math.pi),
    'moon': (lambda t: observe(earth,     _planets['moon'], t).radians),
    'venus': (lambda t: observe(earth,  _planets['venus'], t).radians),
    'mars': (lambda t: observe(earth,  _planets['mars'], t).radians),
    'jupiter': (lambda t: observe(earth,    _planets['jupiter'], t).radians)
}

def generate_table(dates):

    new_table = {}
    new_table['t'] = dates

    for b in bodies:
        new_table[b] = [] # assign body nae as key
        for t in dates: # calculate for every date in dates
            body_pos = positions[b](t) # calculate position, using this planet of body
            new_table[b].append( body_pos ) # generate a new table

    df = pd.DataFrame(data=new_table)

    return df

df = generate_table(dates)
df.sample(15)
Out[102]:
t sun earth moon venus mars jupiter
149690 2004-02-26 04:00:00+00:00 5.878904 2.737311 0.791900 0.353795 0.776064 2.876731
125890 1998-09-21 20:00:00+00:00 3.118022 -0.023571 3.334024 2.943443 2.449233 6.149105
73922 1986-11-13 04:00:00+00:00 4.025802 0.884210 0.223293 3.812943 5.612511 5.989845
67042 1985-04-18 20:00:00+00:00 0.504923 -2.636670 0.242316 0.121726 0.958782 5.477937
4485 1971-01-09 18:00:00+00:00 5.048080 1.906488 1.539050 4.238912 4.049131 4.181739
160677 2006-08-29 18:00:00+00:00 2.725605 -0.415987 3.856335 2.454635 3.034209 3.891856
92640 1991-02-20 00:00:00+00:00 5.776359 2.634766 0.621809 6.234074 1.220381 2.198069
182368 2011-08-11 08:00:00+00:00 2.411440 -0.730153 5.047272 2.386536 1.660161 0.691000
52811 1982-01-18 22:00:00+00:00 5.214145 2.072552 4.012284 5.285399 3.382649 3.815142
91068 1990-10-12 00:00:00+00:00 3.465056 0.323463 2.083998 3.372365 1.293873 2.270147
54881 1982-07-10 10:00:00+00:00 1.886211 -1.255382 5.821416 1.360564 3.447698 3.681313
4045 1970-12-04 02:00:00+00:00 4.396647 1.255054 5.562625 3.846233 3.643345 4.054375
207864 2017-06-05 00:00:00+00:00 1.296716 -1.844876 3.566335 0.497138 1.570336 3.368608
29712 1976-10-12 00:00:00+00:00 3.475150 0.333557 1.050762 4.008650 3.708085 1.059559
48637 1981-02-05 02:00:00+00:00 5.523161 2.381568 5.558185 5.258744 5.738473 3.324048
In [104]:
df.to_csv('planets.csv', sep=';')
In [ ]: